#include "ch.h"
#include "hal.h"

#include "debug.h"
#include "threads.h"
#include "ov5640.h"
#include "pi2c.h"
#include "ssdv.h"
#include "aprs.h"
#include "radio.h"
#include "base91.h"
#include <string.h>
#include "types.h"
#include "sleep.h"
#include "watchdog.h"
#include "flash.h"

const uint8_t noCameraFound[4071] = {
	0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48,
	0x00, 0x48, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x43, 0x00, 0x10, 0x0B, 0x0C, 0x0E, 0x0C, 0x0A, 0x10,
	0x0E, 0x0D, 0x0E, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28, 0x1A, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23,
	0x25, 0x1D, 0x28, 0x3A, 0x33, 0x3D, 0x3C, 0x39, 0x33, 0x38, 0x37, 0x40, 0x48, 0x5C, 0x4E, 0x40,
	0x44, 0x57, 0x45, 0x37, 0x38, 0x50, 0x6D, 0x51, 0x57, 0x5F, 0x62, 0x67, 0x68, 0x67, 0x3E, 0x4D,
	0x71, 0x79, 0x70, 0x64, 0x78, 0x5C, 0x65, 0x67, 0x63, 0xFF, 0xDB, 0x00, 0x43, 0x01, 0x11, 0x12,
	0x12, 0x18, 0x15, 0x18, 0x2F, 0x1A, 0x1A, 0x2F, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63, 0x63, 0x63,
	0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
	0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
	0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0xFF, 0xC0,
	0x00, 0x11, 0x08, 0x00, 0x80, 0x00, 0xA0, 0x03, 0x01, 0x11, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11,
	0x01, 0xFF, 0xC4, 0x00, 0x1B, 0x00, 0x00, 0x02, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x04, 0x05, 0x07, 0x06, 0x01, 0xFF, 0xC4,
	0x00, 0x47, 0x10, 0x00, 0x00, 0x05, 0x02, 0x02, 0x05, 0x05, 0x0C, 0x06, 0x09, 0x05, 0x01, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11, 0x12, 0x21, 0x06, 0x13, 0x31, 0x41,
	0x81, 0x14, 0x15, 0x16, 0x42, 0x51, 0x22, 0x32, 0x53, 0x54, 0x61, 0x71, 0x91, 0x92, 0xA1, 0xC1,
	0xE1, 0xE2, 0x36, 0x55, 0x63, 0x93, 0xA3, 0xB3, 0x23, 0x24, 0x52, 0x62, 0x64, 0x65, 0xA2, 0xB1,
	0xD1, 0x07, 0x35, 0x43, 0x74, 0x82, 0xB2, 0xFF, 0xC4, 0x00, 0x1A, 0x01, 0x01, 0x01, 0x00, 0x03,
	0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x02, 0x03,
	0x04, 0x06, 0x01, 0xFF, 0xC4, 0x00, 0x39, 0x11, 0x01, 0x00, 0x00, 0x03, 0x04, 0x06, 0x07, 0x05,
	0x08, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x11, 0x05, 0x12, 0x51, 0xC1,
	0x03, 0x04, 0x13, 0x31, 0x42, 0x81, 0x14, 0x15, 0x21, 0x43, 0x52, 0xA1, 0xE1, 0x06, 0x32, 0x33,
	0x61, 0x62, 0x16, 0x22, 0x41, 0x63, 0x71, 0x82, 0xA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00, 0x1F, 0x40, 0x01, 0x5D, 0xE9, 0x8D, 0x5A, 0x7F, 0x87, 0x16, 0x33, 0x6E,
	0x2C, 0x4F, 0x69, 0x00, 0x00, 0x11, 0x5E, 0xE0, 0x02, 0x37, 0x80, 0x6A, 0x37, 0x80, 0x17, 0xB8,
	0x04, 0x00, 0x00, 0x1A, 0x3B, 0x5C, 0xC0, 0x00, 0x03, 0xAA, 0x68, 0x47, 0xD1, 0x48, 0x5E, 0x77,
	0x3F, 0x31, 0x43, 0x97, 0x49, 0xEF, 0x45, 0xBE, 0x5D, 0xCD, 0xE1, 0x83, 0x20, 0x00, 0x01, 0xC3,
	0x0B, 0x61, 0x0A, 0xAD, 0xF0, 0x00, 0xFA, 0x00, 0x0A, 0xEF, 0x4C, 0x6A, 0xD3, 0xFC, 0x38, 0xB1,
	0x9B, 0x71, 0x62, 0x7B, 0x48, 0x00, 0x00, 0x8A, 0xF7, 0x00, 0x11, 0xBC, 0x03, 0x51, 0xBC, 0x00,
	0xBD, 0xC0, 0x20, 0x00, 0x01, 0xFF, 0xD9
};

uint8_t gimage_id; // Global image ID (for all image threads)
mutex_t camera_mtx;
bool camera_mtx_init = false;

/**
  * At EOI or if picture is cut prematurely, when buffer has to be flushed
  * so all packets are transmitted.
  */
static void flush_ssdv_buffer(prot_t protocol, ax25_t *ax25_handle, radioMSG_t *msg)
{
	switch(protocol) {
		case PROT_APRS_2GFSK:
		case PROT_APRS_AFSK:
			if(protocol == PROT_APRS_2GFSK || protocol == PROT_APRS_AFSK)
				msg->bin_len = aprs_encode_finalize(ax25_handle);

			transmitOnRadio(msg, false);
			break;

		case PROT_SSDV_2FSK:
			transmitOnRadio(msg, false);
			msg->bin_len = 0;
			break;

		default: break;
	}
}

void encode_ssdv(const uint8_t *image, uint32_t image_len, module_conf_t* conf, uint8_t image_id, bool redudantTx)
{
	ssdv_t ssdv;
	uint8_t pkt[SSDV_PKT_SIZE];
	uint8_t pkt_base91[256];
	const uint8_t *b;
	uint32_t bi = 0;
	uint8_t c = SSDV_OK;
	uint16_t i = 0;

	// Init SSDV (FEC at 2FSK, non FEC at APRS)
	bi = 0;
	ssdv_enc_init(&ssdv, conf->protocol == PROT_SSDV_2FSK ? SSDV_TYPE_NORMAL : SSDV_TYPE_PADDING, conf->ssdv_conf.callsign, image_id, conf->ssdv_conf.quality);
	ssdv_enc_set_buffer(&ssdv, pkt);

	// Init transmission packet
	radioMSG_t msg;
	uint8_t buffer[conf->packet_spacing ? 2048 : 8192];
	msg.buffer = buffer;
	msg.bin_len = 0;
	msg.freq = &conf->frequency;
	msg.power = conf->power;

	ax25_t ax25_handle;
	if(conf->protocol == PROT_APRS_2GFSK || conf->protocol == PROT_APRS_AFSK)
	{
		msg.mod = conf->protocol == PROT_APRS_AFSK ? MOD_AFSK : MOD_2GFSK;
		msg.afsk_conf = &(conf->afsk_conf);
		msg.gfsk_conf = &(conf->gfsk_conf);
		aprs_encode_init(&ax25_handle, buffer, sizeof(buffer), msg.mod);
	}

	while(true)
	{
		conf->wdg_timeout = chVTGetSystemTimeX() + S2ST(600); // TODO: Implement more sophisticated method

		while((c = ssdv_enc_get_packet(&ssdv)) == SSDV_FEED_ME)
		{
			b = &image[bi];
			uint8_t r = bi < image_len-128 ? 128 : image_len - bi;
			bi += r;

			if(r <= 0)
			{
				TRACE_ERROR("SSDV > Premature end of file");
				flush_ssdv_buffer(conf->protocol, &ax25_handle, &msg);
				break;
			}
			ssdv_enc_feed(&ssdv, b, r);
		}

		if(c == SSDV_EOI)
		{
			TRACE_INFO("SSDV > ssdv_enc_get_packet said EOI");
			flush_ssdv_buffer(conf->protocol, &ax25_handle, &msg);
			break;
		} else if(c != SSDV_OK) {
			TRACE_ERROR("SSDV > ssdv_enc_get_packet failed: %i", c);
			flush_ssdv_buffer(conf->protocol, &ax25_handle, &msg);
			return;
		}

		switch(conf->protocol) {
			case PROT_APRS_2GFSK:
			case PROT_APRS_AFSK:
				// Encode packet
				TRACE_INFO("IMG  > Encode APRS/SSDV packet");

				// Sync byte, CRC and FEC of SSDV not transmitted (because its not neccessary inside an APRS packet)
				base91_encode(&pkt[6], pkt_base91, 174);

				aprs_encode_data_packet(&ax25_handle, 'I', &conf->aprs_conf, pkt_base91, strlen((char*)pkt_base91));
				if(redudantTx)
					aprs_encode_data_packet(&ax25_handle, 'I', &conf->aprs_conf, pkt_base91, strlen((char*)pkt_base91));

				// Transmit if buffer is almost full or if single packet transmission is activated (packet_spacing != 0)
				// or if AFSK is selected (because the encoding takes a lot of buffer)
				if(ax25_handle.size >= 58000 || conf->packet_spacing || conf->protocol == PROT_APRS_AFSK)
				{
					// Transmit packets
					flush_ssdv_buffer(conf->protocol, &ax25_handle, &msg);

					// Initialize new packet buffer
					aprs_encode_init(&ax25_handle, buffer, sizeof(buffer), msg.mod);

					if(!conf->packet_spacing)
						chThdSleepMilliseconds(6000);
				}
				break;

			case PROT_SSDV_2FSK:
				msg.mod = MOD_2FSK;
				msg.fsk_conf = &(conf->fsk_conf);

				// Encode packet
				TRACE_INFO("IMG  > Encode 2FSK/SSDV packet");
				memcpy(&msg.buffer[msg.bin_len/8], pkt, sizeof(pkt));
				msg.bin_len += 8*sizeof(pkt);
				if(redudantTx)
				{
					memcpy(&msg.buffer[msg.bin_len/8], pkt, sizeof(pkt));
					msg.bin_len += 8*sizeof(pkt);
				}

				// Transmit
				if(msg.bin_len >= 32768 || conf->packet_spacing) // Transmit if buffer is full or if single packet transmission activation (packet_spacing != 0)
					flush_ssdv_buffer(conf->protocol, NULL, &msg);

				break;

			default:
				TRACE_ERROR("IMG  > Unsupported protocol selected for module IMAGE");
		}

		chThdSleepMilliseconds(100);

		// Packet spacing (delay)
		if(conf->packet_spacing)
			chThdSleepMilliseconds(conf->packet_spacing);

		i++;
	}
}

/**
  * Analyzes the image for JPEG errors. Returns true if the image is error free.
  */
static bool analyze_image(uint8_t *image, uint32_t image_len)
{
	return true;
	#if !OV5640_USE_DMA_DBM
	if(image_len >= 65535)
	{
		TRACE_ERROR("CAM  > Camera has %d bytes allocated but DMA DBM not activated", image_len);
		TRACE_ERROR("CAM  > DMA can only use 65535 bytes only");
		image_len = 65535;
	}
	#endif

	ssdv_t ssdv;
	uint8_t pkt[SSDV_PKT_SIZE];
	uint8_t *b;
	uint32_t bi = 0;
	uint16_t i = 0;
	uint8_t c = SSDV_OK;

	ssdv_enc_init(&ssdv, SSDV_TYPE_NOFEC, "", 0, 7);
	ssdv_enc_set_buffer(&ssdv, pkt);

	while(true) // FIXME: I get caught in these loops occasionally and never return
	{
		while((c = ssdv_enc_get_packet(&ssdv)) == SSDV_FEED_ME)
		{
			b = &image[bi];
			uint8_t r = bi < image_len-128 ? 128 : image_len - bi;
			bi += r;
			if(r <= 0)
			{
				TRACE_ERROR("CAM  > Error in image (Premature end of file %d)", i);
				return false;
			}
			ssdv_enc_feed(&ssdv, b, r);
		}

		if(c == SSDV_EOI) // End of image
			return true;

		if(c != SSDV_OK) // Error in JPEG image
		{
			TRACE_ERROR("CAM  > Error in image (ssdv_enc_get_packet failed: %d %d)", c, i);
			return false;
		}

		i++;
		chThdSleepMilliseconds(5);
	}
}

static bool camInitialized = false;

bool takePicture(ssdv_conf_t *conf, bool enableJpegValidation)
{
	bool camera_found = false;

	// Initialize mutex
	if(!camera_mtx_init)
		chMtxObjectInit(&camera_mtx);
	camera_mtx_init = true;

	// Lock camera
	TRACE_INFO("IMG  > Lock camera");
	chMtxLock(&camera_mtx);

	// Detect camera
	if(camInitialized || OV5640_isAvailable()) { // OV5640 available

		TRACE_INFO("IMG  > OV5640 found");
		camera_found = true;

		// Lock Radio (The radio uses the same DMA for SPI as the camera)
		lockRadioByCamera(); // Lock radio

		uint8_t cntr = 5;
		bool jpegValid;
		do {
			// Init camera
			if(!camInitialized) {
				OV5640_init();
				camInitialized = true;
			}

			// Sample data from pseudo DCMI through DMA into RAM
			conf->size_sampled = OV5640_Snapshot2RAM(conf->ram_buffer, conf->ram_size, conf->res);

			// Switch off camera
			if(!keep_cam_switched_on) {
				OV5640_deinit();
				camInitialized = false;
			}

			// Validate JPEG image
			if(enableJpegValidation)
			{
				TRACE_INFO("CAM  > Validate integrity of JPEG");
				jpegValid = analyze_image(conf->ram_buffer, conf->ram_size);
				TRACE_INFO("CAM  > JPEG image %s", jpegValid ? "valid" : "invalid");
			} else {
				jpegValid = true;
			}
		} while(!jpegValid && cntr--);

		// Unlock radio
		unlockRadio();

	} else { // Camera not found

		camInitialized = false;
		TRACE_ERROR("IMG  > No camera found");

	}

	// Unlock camera
	TRACE_INFO("IMG  > Unlock camera");
	chMtxUnlock(&camera_mtx);

	return camera_found;
}

THD_FUNCTION(imgThread, arg)
{
	module_conf_t* conf = (module_conf_t*)arg;

	conf->wdg_timeout = chVTGetSystemTimeX() + S2ST(1200);
	if(conf->init_delay) chThdSleepMilliseconds(conf->init_delay);
	TRACE_INFO("IMG  > Startup image thread");

	systime_t time = chVTGetSystemTimeX();
	while(true)
	{
		TRACE_INFO("IMG  > Do module IMAGE cycle");
		conf->wdg_timeout = chVTGetSystemTimeX() + S2ST(600); // TODO: Implement more sophisticated method

		if(!p_sleep(&conf->sleep_conf))
		{
			// Take picture
			bool camera_found = takePicture(&conf->ssdv_conf, true);
			gimage_id++; // Increase SSDV image counter

			// Radio transmission
			if(camera_found) {
				TRACE_INFO("IMG  > Encode/Transmit SSDV ID=%d", gimage_id-1);
				encode_ssdv(conf->ssdv_conf.ram_buffer, conf->ssdv_conf.size_sampled, conf, gimage_id-1, conf->ssdv_conf.redundantTx);
			} else { // No camera found
				TRACE_INFO("IMG  > Encode/Transmit SSDV (no cam found) ID=%d", gimage_id-1);
				encode_ssdv(noCameraFound, sizeof(noCameraFound), conf, gimage_id-1, conf->ssdv_conf.redundantTx);
			}
		}

		time = waitForTrigger(time, &conf->trigger);
	}
}

void start_image_thread(module_conf_t *conf)
{
	chsnprintf(conf->name, sizeof(conf->name), "IMG");
	thread_t *th = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(conf->packet_spacing ? 6*1024 : 12*1024), "IMG", NORMALPRIO, imgThread, conf);
	if(!th) {
		// Print startup error, do not start watchdog for this thread
		TRACE_ERROR("IMG  > Could not startup thread (not enough memory available)");
	} else {
		register_thread_at_wdg(conf);
		conf->wdg_timeout = chVTGetSystemTimeX() + S2ST(1) + MS2ST(conf->init_delay);
	}
}

